(*****************************************************************************
 * Delphi Plug-in Framework (DPF)
 * Copyright (C) 2006-2007 Tao Yuan
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the
 * License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.                                                               }
 *
 * The Initial Developer of the Original Code is Tao Yuan. Portions created by
 * Tao Yuan are Copyright (C) Tao Yuan (taoy.cn att gmail dott com)
 * All rights reserved.
 *****************************************************************************)
unit RDPluginLifecycleHandler;

interface

uses
  Rcl, Classes, RdClasses,
  RDPluginService, RDPluginRegistry, RDPluginManager;

type
(**
 * Manager class that handles plug-in life cycle related logic. This class is
 * part of standard implementation of plug-in manager, other implementations may
 * not use it at all. The main purpose of this class is to simplify
 * customization of plug-in manager behavior.
 * @version $Id: PluginLifecycleHandler.java,v 1.2 2005/12/03 16:06:20 ddimon Exp $
 *)
 TPluginLifecycleHandler = class(TRdLogPersistent)
 private
   manager: TPluginManager;


 protected
    (**
     * Should dispose all resources allocated by this handler instance. No
     * methods will be called for this class instance after executing this
     * method.
     *)
//   procedure dispose();
 public
    (**
     * This method will be called by {@link PluginManager} just after stopping
     * plug-in. Put here any "un-initializing" logic that should be executed
     * after plug-in stop.
     * @param plugin plug-in being stopping
     * @throws PluginLifecycleException if plug-in can't be "un-initialized"
     *)
   procedure afterPluginStop(PluginInfo: IPluginInfo); virtual; abstract;
    (**
     * This method will be called by {@link PluginManager} just before starting
     * plug-in. Put here any "initializing" logic that should be executed before
     * plug-in start.
     * @param plugin plug-in being starting
     * @throws PluginLifecycleException if plug-in can't be "initialized"
     *)
   procedure beforePluginStart(PluginInfo: IPluginInfo); virtual; abstract;
    (**
     * Configures this handler instance. Note that this method should be called
     * once before {@link #init(PluginManager)}, usually this is done in
     * {@link ObjectFactory object factory} implementation.
     * @param config handler configuration data
     *)
   procedure configure(config: TExtendedProperties); virtual; abstract;
    (**
     * This method should create new instance of class loader for given plug-in. 
     * @param descr plug-in descriptor
     * @return class loader instance for given plug-in
     *)
   function createPluginLoader(descr: IPluginDescriptor): TPluginLoader; virtual;
       abstract;
    (**
     * This method should create new instance of plug-in class. No initializing
     * logic should be executed in new class instance during this method call.
     * <br>
     * Note that this method will NOT be called for those plug-ins that have NO
     * class declared in plug-in descriptor i.e., method
     * {@link PluginDescriptor#getPluginClassName()} returns blank string or
     * <code>null</code>.
     * @param descr plug-in descriptor
     * @return new not initialized instance of plug-in class
     * @throws PluginLifecycleException if plug-in class can't be instantiated
     *         for some reason
     *)
   function createPluginInstance(descr: IPluginDescriptor): IPluginInfo; virtual;
       abstract;
    (**
     * @return instance of plug-in manager, this handler is "connected" to
     *)
   function getPluginManager: TPluginManager;
    (**
     * Initializes this handler instance. This method called once during this
     * handler instance life cycle.
     * @param aManager a plug-in manager, this handler is "connected" to
     *)
   procedure init(aManager: TPluginManager);
end;

implementation

function TPluginLifecycleHandler.getPluginManager: TPluginManager;
begin
  Result := manager;
end;

procedure TPluginLifecycleHandler.init(aManager: TPluginManager);
begin
  manager := aManager;
end;

end.
